import BaseSearchTable from '@/components/BaseSearchTable';
import CommonTag from '@/page-components/CommonTag';
import services from '@/services/demo';
import { getItem } from '@/utils/utils';
import { history } from '@umijs/max';
import { Space } from 'antd';
import { useRef, useState } from 'react';
import { statusOptions, typeOptions } from './constant';
const { deleteUser, modifyUser, getList } = services.UserController;
const Index = () => {
  const getTableData = async (params) => {
    // console.log(params)
    let payload = {
      ...params,
      pageSize: params.pageSize,
      pageNum: params.current,
    };
    delete payload.current;
    const res = await getList(payload);
    return {
      data: res.data.records,
      success: true,
      total: res.data.total,
    };
  };
  const formRef = useRef();
  const [dataSource, setDataSource] = useState([]);
  const [total, setTotal] = useState(0);
  const [name, setName] = useState('维保');
  // const {
  //   search: { reset, submit },
  //   tableProps,
  // } = useAntdTable(getTableData, {
  //   form: formRef?.current,
  //   // defaultParams: {
  //   //   pageNum: 1,
  //   //   pageSize: 30,
  //   // },
  //   dataSource,
  //   total,
  // });

  const columns = [
    {
      title: `${name}计划编码`,
      dataIndex: 'code',
      width: 180,
    },
    {
      title: `${name}计划名称`,
      dataIndex: 'name',
      width: 180,
    },
    {
      title: `${name}类型`,
      dataIndex: 'typeName',
      valueType: 'select',
      fieldProps: {
        options: typeOptions,
      },
      width: 180,
    },
    {
      title: `${name}频次`,
      dataIndex: 'period',
      hideInSearch: true,
      width: 180,
    },
    {
      title: `初次${name}日期`,
      dataIndex: 'recordTime',
      // render: (_, record) => <div>{formatTimeToDate(_)}</div>,
      width: 180,
      hideInSearch: true,
    },
    {
      title: `${name}人员`,
      dataIndex: 'nickName',
      width: 180,
    },
    {
      title: `${name}人联系方式`,
      dataIndex: 'phonenumber',
      width: 180,
    },
    {
      title: '计划状态',
      dataIndex: 'status',
      width: 180,
      fieldProps: {
        options: statusOptions,
      },
      valueType: 'select',
      render: (_) => (
        <CommonTag color={getItem(statusOptions, _, 'color')}>
          {_ === 'ENABLE' ? '已启用' : '未启用'}
        </CommonTag>
      ),
    },
    {
      title: '更新时间',
      dataIndex: 'updateTime',
      // render: (_, record) => <div>{formatTimeToDateSecond(_)}</div>,
      width: 110,
      hideInSearch: true,
      hideInForm: true,
    },
    {
      title: '操作',
      key: 'action',
      fixed: 'right',
      width: 200,
      align: 'center',
      hideInSearch: true,
      hideInForm: true,
      render: (_, record) => (
        <div>
          <Space size={10}>
            <a
              onClick={() => {
                history.push(`/back/protable/detail?id=${record.id}`);
              }}
            >
              详情
            </a>
            <a
              onClick={() => {
                history.push(
                  `/back/protable/edit?id=${record.id}`,
                );
              }}
            >
              编辑
            </a>
            {/* <OpenPlan
              id={record?.id}
              text={record?.status === 'DISABLE' ? '启用' : '停用'}
              reFun={() => reset()}
            />
            <DeleteBtn id={record.id} reFun={() => refresh()} /> */}
          </Space>
        </div>
      ),
    },
  ];

  return (
    <div>
      <BaseSearchTable
        // {...tableProps}
        columns={columns}
        // submit={submit}
        // reset={reset}
        formRef={formRef}
        request={getTableData}
        // loading={true}
      ></BaseSearchTable>
    </div>
  );
};
export default Index;
